<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="国家级专家" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointA',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
        <a-form-item label="省级专家" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointB',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
        <a-form-item label="正高" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointC',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
        <a-form-item label="副高" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointD',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
        <a-form-item label="中级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointE',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
        <a-form-item label="初级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pointF',{ rules: [
        { required: true, message: '请输入0~100的整数' },
        { validator: checkPositiveInteger }]
       }]" placeholder="请输入此专家分数"></a-input>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import DynamicForm from '../modules/DynamicForm'
import {httpAction, postAction,getAction} from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JUpload from '@/components/jeecg/JUpload'
import JCategorySelect from '@/components/jeecg/JCategorySelect'
import JDate from '@/components/jeecg/JDate'
export default { name: "infoModal",

  components: {
    JUpload,
    JCategorySelect,
    JDate,
    DynamicForm,
  },
  data () {
    return {
      id : '1',
      projectinfo:{},
      form: this.$form.createForm(this),
      title:"操作",
      width:800,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/org/diyProfessorInfo2/add",
      },
      childArray:[],
    }
  },
  created () {
  },
  methods: {
    checkPositiveInteger(rule, value, callback){
      const number = Number(value);
      console.log(number)
      if (!Number.isInteger(number) || number < 0 ) {
        // 如果需要返回 error msg，就把它传给 `callback()`
        callback('请输入0~100的整数');
      }
      if (!Number.isInteger(number) || number >100 ) {
        // 如果需要返回 error msg，就把它传给 `callback()`
        callback('请输入0~100的整数');
      } else {
        // 如果通过校验，调用无参数的 `callback()` 即可
        callback();
      }

    },
    add () {
      console.log("+++++++1")
      this.edit1({});
      this.childArray=[];
    },
    edit1 (record) {
      this.form.resetFields();
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model,'pointA','pointB','pointC','pointD','pointE','pointF'))
      })
    },

    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        let formData = Object.assign(this.model, values);

        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if(!this.model.id){
            httpurl+=this.url.add;
            method = 'post';
          }
          console.log("表单提交数据",formData)

          httpAction(httpurl,formData,method).then((res)=>{
            if(res.success){
              that.$message.success("操作成功!");
              that.$emit('ok');
              this.reload();

            }else{
              that.$message.warning("操作失败!");
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }

      })
    },
    handleCancel () {
      this.close()
    },
    popupCallback(row){
      this.form.setFieldsValue(pick(row,'pointA','pointB','pointC','pointD','pointE','pointF'))
    },


  }
}
</script>
<style>
.ant-form-item-label{
  padding-top: 0px!important;
}
</style>